var ModuleUtil = {
  getPurchaseOrderData: function (postData, user) {
    var orderIds = postData.orderIds;
    return ajaxRequest('purchaseOrder/getPurchaseOrderList', postData).then(function (res) {
      var orders;
      if (_.isArray(res)) {
        orders = res;
      } else {
        orders = res.returnData;
      }

      if (!SysUtil.isEmpty(orderIds)) {
        orderIds = orderIds.split(',');
        orders = _.filter(orders, function(order){
          return orderIds.indexOf(order.purchaseDetailId) !== -1;
        });
      }

      orderList = [];
      for (var i = 0; i < orders.length; i++) {
        var order = orders[i];
        var orderObj = new Order(order, user);
        orderList.push(orderObj);
      }

      var purchaseNoObj = res.ptMap;
      if (purchaseNoObj === null) {
        purchaseNoObj = {};
      }
      return {
        totalCount: res.iTotalRecords,
        orderList: orderList,
        purchaseNoObj: purchaseNoObj
      };
    }).catch(function () {
      return {
        totalCount: 0,
        orderList: [],
        purchaseNoObj: {}
      };
    });
  },

  getFeedMaterialDetail: function (postData, feed, mode) {
    return ajaxRequest('basicData/getCompanyMaterialListByDetail', postData).then(function (data) {
      if (data === null) {
        return null;
      }

      var materialDetailList = [];
      for (var i = 0; i < data.length; i++) {
        var detail = data[i];
        if (SysUtil.isEmpty(detail.materialCode)) {
          continue;
        }
        detail = new FeedMaterialDetailModel(detail, feed, mode);
        materialDetailList.push(detail);
      }
      return materialDetailList;
    });
  }
};